package org.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
public class AspectDemo {
    @Pointcut("execution(* org.example.aop.controller.*.*(..))")
    //@Pointcut("execution(* org.example.aop.controller..*(..))")
    public  void pt() {} ;
    @Before("pt()")
    public void doBefore(){
        log.info("AspectDemo do before..");
    }
    @After("pt()")
    public void doAfter(){
        log.info("AspectDemo do after..");
    }
    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("AspectDemo do around before...");
        Object result = null;
        try{
            result = joinPoint.proceed();
        }catch (Exception e){
            log.error("do around 执行目标函数，内部发生异常"+e);
            
        }

        log.info("AspectDemo do around after...");
         return result;
    }
    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("AspectDemo do after returning");
    }
    @AfterThrowing("pt()")
    public void doAterThrowing(){
        log.info("AspectDemo do atfet throwing");
    }




}
